package com.ekuaitu.kuaitustaff.baiduMap;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.CircleOptions;
import com.baidu.mapapi.map.InfoWindow;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.Overlay;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.map.PolylineOptions;
import com.baidu.mapapi.map.Stroke;
import com.baidu.mapapi.model.LatLng;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.ekuaitu.kuaitustaff.R;
import com.ekuaitu.kuaitustaff.activity.PhotoViewActivity;
import com.ekuaitu.kuaitustaff.api.ApiService;
import com.ekuaitu.kuaitustaff.api.ApiStore;
import com.ekuaitu.kuaitustaff.api.UrlConstant;
import com.ekuaitu.kuaitustaff.application.MyApplication;
import com.ekuaitu.kuaitustaff.bean.CarOrderBean;
import com.ekuaitu.kuaitustaff.bean.CarQueryStationBean;
import com.ekuaitu.kuaitustaff.bean.CarTrackBean;
import com.ekuaitu.kuaitustaff.bean.MakerIconBean;
import com.ekuaitu.kuaitustaff.bean.SpecialOrderBean;
import com.ekuaitu.kuaitustaff.utils.Logger;
import com.ekuaitu.kuaitustaff.utils.ThreadPool;
import com.ekuaitu.kuaitustaff.widget.MarqueeTextview;
import com.google.gson.JsonObject;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class MarkerUtils {
    private Context mContext;
    private BaiduMap mBaiduMap;
    private List<Overlay> parksAndCarsMarkerList = new ArrayList<>();
    private List<Overlay> specialOrderList = new ArrayList<>();
    private List<Overlay> stationMarkerList = new ArrayList<>();
    private List<Overlay> oneMarkerList = new ArrayList<>();
    private OverlayOptions stoppop;
    private Map<String, Bitmap> allMarkerTypeBitMap = new HashMap<>();
    public Map<String, String> picMap = new HashMap<>();

    public MarkerUtils(BaiduMap mBaiduMap, Context mContext) {
        this.mContext = mContext;
        this.mBaiduMap = mBaiduMap;
    }

    ////标识marker类型
    public enum MarkerType {
        CAR,//车辆
        END_POSITION_MARKER,//终点marker
        QUERY_LICENSE,//搜索
        ONEKEYRECEIVE_CAR,//一键接单
        STATION_POSITION_MARKER, //加油站或者充电桩
        LAST_USER_PHONE,//
        WASH_CAR,//
        SPECIAL_ORDER//送车上门工单展示

    }

    /**
     * 添加电动车工单marker
     */

    public void addCarMarkersToMap(List<CarOrderBean.AttachmentBean> carsResultList) {
        if (allMarkerTypeBitMap.isEmpty()) {
            new ApiStore().getRetrofit(UrlConstant.Request.BASE_URL_NEW, "", "").create(ApiService.class).getMakerIcon(MyApplication.getInstance().getRequestFieldMap()).enqueue(new Callback<MakerIconBean>() {
                @Override
                public void onResponse(Call<MakerIconBean> call, Response<MakerIconBean> response) {
                    if (response.isSuccessful() && response.body() != null) {
                        if (response.body().getErrCode() == 0 && response.body().getAttachment().size() != 0) {
                            for (int i = 0; i < response.body().getAttachment().size(); i++) {
                                picMap.put(response.body().getAttachment().get(i).getTaskType() + "", response.body().getAttachment().get(i).getSmall());
                            }
                            new DownLoadImage().downLoadPic((HashMap<String, String>) picMap, new DownLoadImage.IDownLoadImage() {
                                @Override
                                public void onDownLoadDone(HashMap<String, Bitmap> loadedBitmaps) {
                                    allMarkerTypeBitMap = loadedBitmaps;
                                    addMakers(carsResultList);
                                }
                            });

                        }
                    }
                }

                @Override
                public void onFailure(Call<MakerIconBean> call, Throwable t) {

                }
            });
        } else {
            addMakers(carsResultList);
        }

    }

    private void addMakers(List<CarOrderBean.AttachmentBean> carsResultList) {
        ThreadPool.execute(new Runnable() {
            @Override
            public void run() {
                parksAndCarsMarkerList.clear();
                for (int i = 0; i < carsResultList.size(); i++) {
                    if (carsResultList.get(i) != null) {
                        Bundle bundle = new Bundle();
                        bundle.putString("markerType", MarkerType.CAR.name()); //标识Marker类型
                        bundle.putInt("carMarkerId", i); //标识marker的序号，用于点击后获取相应的数据

                        View carMarkerView;
                        if ("22".equals(carsResultList.get(i).getTaskType())) {
                            carMarkerView = View.inflate(mContext, R.layout.car_marker2, null);
                        } else if (carsResultList.get(i).getIsBigPic() == 1) {
                            carMarkerView = View.inflate(mContext, R.layout.car_marker1, null);
                        } else {
                            carMarkerView = View.inflate(mContext, R.layout.car_marker, null);
                        }
                        ImageView imageView = (ImageView) carMarkerView.findViewById(R.id.imageView);
                        if (null != allMarkerTypeBitMap.get(carsResultList.get(i).getTaskType())) {
                            imageView.setImageBitmap(allMarkerTypeBitMap.get(carsResultList.get(i).getTaskType()));
                        } else {
                            imageView.setImageResource(R.drawable.park_marker);
                        }
                        OverlayOptions option = new MarkerOptions()
                                .position(new LatLng(carsResultList.get(i).getLatitude(), carsResultList.get(i).getLongitude()))
                                .icon(BitmapDescriptorFactory
                                        .fromView(carMarkerView))
                                .title(carsResultList.get(i).getParkName())
                                .zIndex(carsResultList.get(i).getLevel())
                                .extraInfo(bundle);
                        parksAndCarsMarkerList.add(mBaiduMap.addOverlay(option));
                    }
                }
            }
        });
    }

    /**
     * 添加充电桩或者加油站
     */

    public void addStationMarkersToMap(List<CarQueryStationBean.AttachmentBean.StationListBean> stationResultList, String type) {
        ThreadPool.execute(new Runnable() {
            @Override
            public void run() {
                List<OverlayOptions> optionsList = new ArrayList<>();
                for (int i = 0; i < stationResultList.size(); i++) {
                    if (stationResultList.get(i) != null) {
                        Bundle bundle = new Bundle();
                        bundle.putString("markerType", MarkerType.STATION_POSITION_MARKER.name()); //标识Marker类型
                        bundle.putInt("carMarkerId", i); //标识marker的序号，用于点击后获取相应的数据
                        if ("1".equals(type)) {
                            OverlayOptions option = new MarkerOptions()
                                    .position(new LatLng(stationResultList.get(i).getLatitude(), stationResultList.get(i).getLongitude()))
                                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_recharge))
                                    .zIndex(3)
                                    .extraInfo(bundle);
                            optionsList.add(option);

                        } else {
                            OverlayOptions option = new MarkerOptions()
                                    .position(new LatLng(stationResultList.get(i).getLatitude(), stationResultList.get(i).getLongitude()))
                                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_petrolstation))
                                    .zIndex(3)
                                    .extraInfo(bundle);
                            optionsList.add(option);
                        }
                    }
                }
                stationMarkerList = mBaiduMap.addOverlays(optionsList);
            }
        });
    }

    //车牌号搜索
    public void addOneCarMarkerToMap(CarOrderBean.AttachmentBean attachmentBean, int type, int carMarkerId) {
        if (allMarkerTypeBitMap.isEmpty()) {
            new ApiStore().getRetrofit(UrlConstant.Request.BASE_URL_NEW, "", "").create(ApiService.class).getMakerIcon(MyApplication.getInstance().getRequestFieldMap()).enqueue(new Callback<MakerIconBean>() {
                @Override
                public void onResponse(Call<MakerIconBean> call, Response<MakerIconBean> response) {
                    if (response.isSuccessful() && response.body() != null) {
                        if (response.body().getErrCode() == 0 && response.body().getAttachment().size() != 0) {
                            for (int i = 0; i < response.body().getAttachment().size(); i++) {
                                picMap.put(response.body().getAttachment().get(i).getTaskType() + "", response.body().getAttachment().get(i).getSmall());
                            }
                            new DownLoadImage().downLoadPic((HashMap<String, String>) picMap, new DownLoadImage.IDownLoadImage() {
                                @Override
                                public void onDownLoadDone(HashMap<String, Bitmap> loadedBitmaps) {
                                    allMarkerTypeBitMap = loadedBitmaps;
                                    addOneMarker(attachmentBean, type, carMarkerId);
                                }
                            });

                        }
                    }
                }

                @Override
                public void onFailure(Call<MakerIconBean> call, Throwable t) {

                }
            });
        } else {
            addOneMarker(attachmentBean, type, carMarkerId);
        }
    }

    private void addOneMarker(CarOrderBean.AttachmentBean attachmentBean, int type, int carMarkerId) {
        Bundle bundle = new Bundle();
        //1：派单  2：搜索
        if (type == 1) {
            bundle.putString("markerType", MarkerType.ONEKEYRECEIVE_CAR.name()); //标识Marker类型
        } else if (type == 2) {
            bundle.putString("markerType", MarkerType.QUERY_LICENSE.name()); //标识Marker类型
        }
        bundle.putInt("carMarkerId", carMarkerId);
        View carMarkerView;
        if ("22".equals(attachmentBean.getTaskType())) {
            carMarkerView = View.inflate(mContext, R.layout.car_marker2, null);
        } else if (attachmentBean.getIsBigPic() == 1) {
            carMarkerView = View.inflate(mContext, R.layout.car_marker1, null);
        } else {
            carMarkerView = View.inflate(mContext, R.layout.car_marker, null);
        }
        ImageView imageView = (ImageView) carMarkerView.findViewById(R.id.imageView);
        if (null != allMarkerTypeBitMap.get(attachmentBean.getTaskType())) {
            imageView.setImageBitmap(allMarkerTypeBitMap.get(attachmentBean.getTaskType()));
        } else {
            imageView.setImageResource(R.drawable.park_marker);
        }
        if (attachmentBean != null) {
            oneMarkerList.add(mBaiduMap.addOverlay(new MarkerOptions()
                    .position(new LatLng(attachmentBean.getLatitude(), attachmentBean.getLongitude()))
                    .icon(BitmapDescriptorFactory
                            .fromView(carMarkerView))
                    .title(attachmentBean.getParkName())
                    .zIndex(3)
                    .extraInfo(bundle)));
        }
    }

    //添加marker
    public void addLastUserPhoneMarkerToMap(LatLng latLng) {
        Bundle bundle = new Bundle();
        bundle.putString("markerType", MarkerType.LAST_USER_PHONE.name()); //标识Marker类型
        RelativeLayout relativeLayout = (RelativeLayout) LayoutInflater.from(mContext).inflate(R.layout.user_phone_marker, null);
        if (latLng != null) {
            mBaiduMap.addOverlay(new MarkerOptions()
                    .position(latLng)
                    .icon(BitmapDescriptorFactory.fromView(relativeLayout))
                    .zIndex(3)
                    .extraInfo(bundle));
        }
    }

    //添加送车上门marker
    public void addSpecialMarkerToMap(List<SpecialOrderBean.AttachmentBean> specialOrderListBean) {
        ThreadPool.execute(new Runnable() {
            @Override
            public void run() {
                removeSpecialOrderMarker();
                List<OverlayOptions> optionsList = new ArrayList<>();
                RelativeLayout relativeLayout = (RelativeLayout) LayoutInflater.from(mContext).inflate(R.layout.special_order_marker, null);
                for (int i = 0; i < specialOrderListBean.size(); i++) {
                    Bundle bundle = new Bundle();
                    bundle.putString("markerType", MarkerType.SPECIAL_ORDER.name()); //标识Marker类型
                    bundle.putInt("carMarkerId", i); //标识marker的序号，用于点击后获取相应的数据
                    OverlayOptions option = new MarkerOptions()
                            .position(new LatLng(specialOrderListBean.get(i).getLat(), specialOrderListBean.get(i).getLng()))
                            .icon(BitmapDescriptorFactory.fromView(relativeLayout))
                            .zIndex(240)
                            .extraInfo(bundle);
                    optionsList.add(option);
                }
                specialOrderList = mBaiduMap.addOverlays(optionsList);
            }
        });
    }

    //导航终点图片
    public void showEndPositionIcon(BaiduMap mBaiduMap, LatLng latLng, int operateRange, final int bitmapResouce) {
        Bundle bundle = new Bundle();
        bundle.putString("markerType", MarkerType.END_POSITION_MARKER.name()); //标识Marker类型
        stoppop = new MarkerOptions().position(latLng).zIndex(250).icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(mContext.getResources(), bitmapResouce))).extraInfo(bundle);
        mBaiduMap.addOverlay(stoppop);

        //终点画圆 寻车界面半径为0 0x2201A4F1
        OverlayOptions ooCircle = new CircleOptions().fillColor(0x222A6CFF)
                .center(latLng).stroke(new Stroke(3, 0xAA296CFF))
                .radius(operateRange);
        mBaiduMap.addOverlay(ooCircle);


    }

    //导航洗车店图片
    public void showWashCarIcon(BaiduMap mBaiduMap, LatLng latLng, final int bitmapResouce) {
        Bundle bundle = new Bundle();
        bundle.putString("markerType", MarkerType.WASH_CAR.name()); //标识Marker类型
        stoppop = new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(mContext.getResources(), bitmapResouce))).extraInfo(bundle);
        mBaiduMap.addOverlay(stoppop);

    }

    public void showLastUserPhoneInfoWindow(String content, LatLng carPosition, final NaviButtonClickListener clickListener) {
        //初始化marker的InfoWindow
        View infoWindow = LayoutInflater.from(mContext).inflate(R.layout.layout_last_user_phone_window, null);
        ImageView navi = (ImageView) infoWindow.findViewById(R.id.navi);
        navi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clickListener.onClick();
            }
        });
        InfoWindow mInfoWindow = new InfoWindow(infoWindow, carPosition,
                -(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 45, mContext.getResources().getDisplayMetrics()));
        mBaiduMap.showInfoWindow(mInfoWindow);
    }

    public void showFindCarInfoWindow(String content, LatLng carPosition, final NaviButtonClickListener clickListener) {
        //初始化marker的InfoWindow
        View infoWindow = LayoutInflater.from(mContext).inflate(R.layout.layout_find_car_window, null);
        TextView location = (TextView) infoWindow.findViewById(R.id.location);
        TextView navi = (TextView) infoWindow.findViewById(R.id.navi);
        location.setText(content);
        navi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clickListener.onClick();
            }
        });
        InfoWindow mInfoWindow = new InfoWindow(infoWindow, carPosition,
                -(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 45, mContext.getResources().getDisplayMetrics()));
        mBaiduMap.showInfoWindow(mInfoWindow);
    }

    public void showFindCarInfoAndRemarkWindow(String userRemark, String remark, String remarkPic, final LatLng markerPosition, int offsetTip, final NaviButtonClickListener clickListener) {
        //初始化marker的InfoWindow
        View infoWindow = LayoutInflater.from(mContext).inflate(R.layout.layout_locationandremark_windows, null);
        RelativeLayout rl_user_commit = (RelativeLayout) infoWindow.findViewById(R.id.rl_user_commit);
        TextView windows_location = (TextView) infoWindow.findViewById(R.id.windows_location);
        MarqueeTextview windows_description = (MarqueeTextview) infoWindow.findViewById(R.id.windows_location_offset);
        TextView navi = (TextView) infoWindow.findViewById(R.id.navi);
        if (remarkPic != null && !remarkPic.equals("") && !remarkPic.equals("0") && remarkPic.split(",").length > 0) {
            ImageView imageView = (ImageView) infoWindow.findViewById(R.id.iv_user_commit);
            imageView.setOnClickListener((View view) -> {
                Intent intent = new Intent(mContext, PhotoViewActivity.class);
                intent.putStringArrayListExtra("pictures", new ArrayList<String>(Arrays.asList(remarkPic.split(","))));
                int location[] = new int[2];
                imageView.getLocationOnScreen(location);
                intent.putExtra("left", location[0]);
                intent.putExtra("top", location[1]);
                intent.putExtra("height", imageView.getHeight());
                intent.putExtra("width", imageView.getWidth());
                mContext.startActivity(intent);
                //((CarNewMainMapActivity) mContext).overridePendingTransition(0, 0);
            });
        } else {
            rl_user_commit.setVisibility(View.GONE);
        }

        if (offsetTip == 0) {
            windows_description.setVisibility(View.VISIBLE);
            windows_description.setText("车辆位置漂移较大");
            windows_description.setTextColor(Color.parseColor("#F2291E"));
        } else if (offsetTip == 2) {
            windows_description.setVisibility(View.VISIBLE);
        } else {
            windows_description.setVisibility(View.GONE);
        }
        if (userRemark != null) {
            windows_location.setText(userRemark);//车辆位置
        }
        //查看备注
        RelativeLayout rl_remark = (RelativeLayout) infoWindow.findViewById(R.id.rl_remark);
        TextView tv_remark = (TextView) infoWindow.findViewById(R.id.tv_remark);
        TextView windows_remark = (TextView) infoWindow.findViewById(R.id.windows_remark);
        windows_remark.setText("查看备注");//设置原来的文本
        windows_remark.setTag(false);//标记textview为false（表示没有被点击过）
        windows_remark.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean flag = (boolean) windows_remark.getTag();//当点击时，首先判断是否已经点击过
                if (!flag) {//没有被点击过
                    rl_remark.setVisibility(View.VISIBLE);
                    if (TextUtils.isEmpty(remark)) {
                        tv_remark.setText("无备注");
                    } else {
                        tv_remark.setText(remark);
                    }
                    windows_remark.setText("关闭备注");
                    windows_remark.setTag(true);
                } else {//已经点击过了
                    rl_remark.setVisibility(View.GONE);

                    windows_remark.setText("查看备注");
                    windows_remark.setTag(false);
                }
                InfoWindow mInfoWindow = new InfoWindow(infoWindow, markerPosition,
                        -(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 55, mContext.getResources().getDisplayMetrics()));
                mBaiduMap.showInfoWindow(mInfoWindow);
            }
        });

        navi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clickListener.onClick();
            }
        });
        InfoWindow mInfoWindow = new InfoWindow(infoWindow, markerPosition,
                -(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 45, mContext.getResources().getDisplayMetrics()));
        mBaiduMap.showInfoWindow(mInfoWindow);
    }


    public void showCarLocationInfoWindow(int distributeReason, String userRemark, String remark, String remarkPic, final LatLng markerPosition, int offsetTip) {
        //初始化marker的InfoWindow
        View infoWindow = LayoutInflater.from(mContext).inflate(R.layout.layout_car_location_windows, null);
        RelativeLayout rl_user_commit = (RelativeLayout) infoWindow.findViewById(R.id.rl_user_commit);
        TextView windows_location = (TextView) infoWindow.findViewById(R.id.windows_location);
        MarqueeTextview windows_description = (MarqueeTextview) infoWindow.findViewById(R.id.windows_location_offset);
        if (remarkPic != null && !remarkPic.equals("") && !remarkPic.equals("0") && remarkPic.split(",").length > 0) {
            ImageView imageView = (ImageView) infoWindow.findViewById(R.id.iv_user_commit);
            imageView.setOnClickListener((View view) -> {
                Intent intent = new Intent(mContext, PhotoViewActivity.class);
                intent.putStringArrayListExtra("pictures", new ArrayList<String>(Arrays.asList(remarkPic.split(","))));
                int location[] = new int[2];
                imageView.getLocationOnScreen(location);
                intent.putExtra("left", location[0]);
                intent.putExtra("top", location[1]);
                intent.putExtra("height", imageView.getHeight());
                intent.putExtra("width", imageView.getWidth());
                mContext.startActivity(intent);
                //((CarNewMainMapActivity) mContext).overridePendingTransition(0, 0);
            });
        } else {
            rl_user_commit.setVisibility(View.GONE);
        }
        if (distributeReason != 0) {
            windows_description.setVisibility(View.VISIBLE);
            windows_description.setText("预估当前车辆不会产生订单，需要调度");
        } else if (offsetTip == 0) {
            windows_description.setVisibility(View.VISIBLE);
            windows_description.setText("车辆位置漂移较大");
            windows_description.setTextColor(Color.parseColor("#F2291E"));
        } else if (offsetTip == 2) {
            windows_description.setVisibility(View.VISIBLE);
        } else {
            windows_description.setVisibility(View.GONE);
        }
        if (userRemark != null) {
            windows_location.setText(userRemark);//车辆位置
        }
        //查看备注
        RelativeLayout rl_remark = (RelativeLayout) infoWindow.findViewById(R.id.rl_remark);
        TextView tv_remark = (TextView) infoWindow.findViewById(R.id.tv_remark);
        TextView windows_remark = (TextView) infoWindow.findViewById(R.id.windows_remark);
        windows_remark.setText("查看备注");//设置原来的文本
        windows_remark.setTag(false);//标记textview为false（表示没有被点击过）
        windows_remark.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean flag = (boolean) windows_remark.getTag();//当点击时，首先判断是否已经点击过
                if (!flag) {//没有被点击过
                    rl_remark.setVisibility(View.VISIBLE);
                    if (TextUtils.isEmpty(remark)) {
                        tv_remark.setText("无备注");
                    } else {
                        tv_remark.setText(remark);
                    }
                    windows_remark.setText("关闭备注");
                    windows_remark.setTag(true);
                } else {//已经点击过了
                    rl_remark.setVisibility(View.GONE);

                    windows_remark.setText("查看备注");
                    windows_remark.setTag(false);
                }
                InfoWindow mInfoWindow = new InfoWindow(infoWindow, markerPosition,
                        -(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 55, mContext.getResources().getDisplayMetrics()));
                mBaiduMap.showInfoWindow(mInfoWindow);
            }
        });
        InfoWindow mInfoWindow = new InfoWindow(infoWindow, markerPosition,
                -(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 55, mContext.getResources().getDisplayMetrics()));
        mBaiduMap.showInfoWindow(mInfoWindow);
    }

    public interface NaviButtonClickListener {
        void onClick();
    }

    public interface EndImageClickListener {
        void onClick();
    }

    /**
     * 清除地图上网点和车辆的Marker
     */
    public void removeParksAndCarsMarker() {

        if (parksAndCarsMarkerList != null && parksAndCarsMarkerList.size() != 0) {
            for (int i = 0; i < parksAndCarsMarkerList.size(); i++) {
                parksAndCarsMarkerList.get(i).remove();
            }
            parksAndCarsMarkerList.clear();
        }

    }

    //清除加油站或充电桩
    public void removeStationMarkers() {
        if (stationMarkerList != null && stationMarkerList.size() != 0) {
            for (int i = 0; i < stationMarkerList.size(); i++) {
                stationMarkerList.get(i).remove();
            }
            stationMarkerList.clear();
        }
    }

    //清除一键接单的marker
    public void removeOneMarker() {
        if (oneMarkerList != null && oneMarkerList.size() != 0) {
            for (int i = 0; i < oneMarkerList.size(); i++) {
                oneMarkerList.get(i).remove();
            }
            oneMarkerList.clear();
        }
    }

    public void removeSpecialOrderMarker() {
        if (specialOrderList != null && specialOrderList.size() != 0) {
            for (int i = 0; i < specialOrderList.size(); i++) {
                specialOrderList.get(i).remove();
            }
            specialOrderList.clear();
        }
    }

    //行驶轨迹
    public void addDriveTracksToMap(List<CarTrackBean.AttachmentBean> carTracksList) {

        List<LatLng> points = new ArrayList<>();
        if (carTracksList.size() >= 2) {
            stoppop = new MarkerOptions().position(new LatLng(carTracksList.get(0).getLatitude(), carTracksList.get(0).getLongitude())).icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_xingcheguiji));
            mBaiduMap.addOverlay(stoppop);
            for (int i = 0; i < carTracksList.size(); i++) {
                points.add(new LatLng(carTracksList.get(i).getLatitude(), carTracksList.get(i).getLongitude()));
            }
            OverlayOptions ooPolyline = new PolylineOptions().width(10).color(Integer.valueOf(mContext.getResources().getColor(R.color.history_tracks))).points(points);
            mBaiduMap.addOverlay(ooPolyline);
        }
    }
}
